<template>
  <div class="page">
    <p class="shoplist">采购单列表</p>

    <div class="header">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="采购状态">
          <el-select v-model="formInline.status" placeholder="请选择">
            <el-option label="发出" value="1"></el-option>
            <el-option label="生成" value="2"></el-option>
             <el-option label="全部" value=""></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="制单人">
          <el-input
            v-model="formInline.supervisorName"
            placeholder="制单人"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="下单日期">
          <el-date-picker
            v-model="formInline.createTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="供货日期">
          <el-date-picker
            v-model="formInline.eliveryTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search()">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table">
      <el-table :data="shopLists" border style="width: 100%;text-align:center">
        <el-table-column type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column prop="purchaseId" label="采购单号"> </el-table-column>
        <el-table-column prop="createTime" label="下单日期"> </el-table-column>
        <el-table-column prop="eliveryTime" label="供货日期"> </el-table-column>
        <el-table-column prop="planPrice" label="计划金额"> </el-table-column>
        <el-table-column prop="supervisorName" label="制单人">
        </el-table-column>
        <el-table-column prop="status" label="采购状态">
          <template slot-scope="scope">
            {{ scope.row.status | statusFitlter }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="200px">
          <template slot-scope="scope">
            <el-button type="primary" @click="shopdetail(scope.row.purchaseId)"
              >明细</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页数据 -->
    <el-pagination
      @current-change="handleCurrentChange"
      background
      :current-page="pagenum"
      :page-size="pagesize"
      layout="prev,pager,next"
      :total="total - 0"
      style="margin-top:20px;text-align:center"
    ></el-pagination>
  </div>
</template>

<script>
import { getshoplist } from "@/api/partner.js";
import { getUserId } from "@/utils/auth";
export default {
  filters: {
    statusFitlter(value) {
      if (value === 1) {
        return "发出";
      } else if (value === 2) {
        return "生成";
      } 
    }
  },
  data() {
    return {
      formInline: {
        eliveryTime: "",
        status: "",
        supervisorName: "",
        createTime: ""
      },
      shopLists: [],
      // 显示第几页
      pagenum: 1,
      total: "",
      // 每页显示的数据
      pagesize: 10
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    // 当前第几页
    handleCurrentChange(val) {
      this.pagenum = val;
      this.init();
    },
    init() {
      var data = {
        supplierId:Number(getUserId()),
        pageNo: this.pagenum
      };
      getshoplist(data).then(res => {
        console.log(res);
        this.shopLists = res.rows;
        this.total = res.total;
        this.pagesize = res.pageSize
      });
    },
    // 搜索
    search() {
      var params = {
        status: this.formInline.status,
        eliveryTime: this.formInline.eliveryTime,
        supervisorName: this.formInline.supervisorName,
        createTime: this.formInline.createTime,
        pageNo: this.pagenum
      };
      getshoplist(params).then(res => {
        console.log(res);
        this.shopLists = res.rows;
        this.total = res.total;
      });
    },
    shopdetail(id) {
      this.$router.push({
        path: "shoppingdetail",
        query: { purchaseId: id }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.page {
  padding: 20px 20px;
  .shoplist {
    font-size: 22px;
    margin-bottom: 60px;
  }
  .header {
    margin-bottom: 70px;
  }
}
</style>
